package com.example.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.example.dao.impl.PeopleDaoImpl;
import com.example.dao.impl.UserDaoImpl;
import com.example.dao.impl.VehicleDaoImpl;
import com.example.dao2.PeopleDao;
import com.example.dao2.UserDao;
import com.example.dao2.VehicleDao;
import com.example.entity.People;
import com.example.entity.User;
import com.example.entity.VehicleFaultInfo;
import com.google.gson.Gson;

public class VehicleFaultInfoServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html"); 
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		//获得打印输出流
		PrintWriter pw=response.getWriter();
		
		//从request中获取相应的属性
		String id=request.getParameter("id");
		if (id==null||id.equals("")) {
			pw.print("error"+"数据为空");	
		}else {
		String name=request.getParameter("name");
		String idno=request.getParameter("idno");
		String vno=request.getParameter("vno");
		String penalty=request.getParameter("penalty");
		String faultRecord=request.getParameter("faultRecord");
		String createTime=request.getParameter("createTime");
		String dealid=request.getParameter("dealid");
		
		VehicleFaultInfo vf=new VehicleFaultInfo();
		vf.setId(id);
		vf.setName(name);
		vf.setIdno(idno);
		vf.setVno(vno);
		vf.setFaultRecord(faultRecord);
		vf.setCreatetime(createTime);
		vf.setPenalty(penalty);
		vf.setDealid(dealid);
	
		VehicleDao vd=new VehicleDaoImpl();
		
		
		if (vd.insert(vf)) {
			pw.print("1");	
			System.out.println("VehicleFaultInfo插入一条数据成功----"+vf.getId());
		}else {
			pw.print("error");	
		}
	
		}
     }

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
            doGet(request, response);
	}
	//初始化方法
	public void init ()throws ServletException{
		
	}
	//构造方法
	public VehicleFaultInfoServlet(){
		super();
	}
	//销毁方法
	public void destory(){
		super.destroy();
	}
public String beanToJson(People people){
	
	Gson gson = new Gson();  
    System.out.println("----------简单对象之间的转化-------------");  
    // 简单的bean转为json  
    String s1 = gson.toJson(people);  
    // System.out.println("简单Bean转化为Json===" + s1);  
    return s1;

}
}
